<template>
  <ex-dialog width="600px" class="ex-diolog" :title="title" :visible="visible" :close-on-click-modal="false"
    @closeDialog="handleClose">
    <div class="main" v-loading="loading">
      <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="140px" class="demo-ruleForm"
        :disabled="disabled">
        <el-form-item label="关联钉钉手机号：" prop="phone">
          <el-input v-model="ruleForm.phone" placeholder="请输入手机号" maxlength="11" clearable  />
        </el-form-item>
      </el-form>
    </div>
    <div class="button_box">
      <el-button type="primary" :loading="AgreeLoading" @click="submitForm('ruleForm')">确认关联</el-button>
    </div>
  </ex-dialog>
</template>
<script>
import Loading from "@/components/Loading/index";
// api
import {
  addDingTalk,
} from "@/api/customer/principalList";
import '@wangeditor/editor/dist/css/style.css'
import {
  Editor,
  Toolbar
} from "@wangeditor/editor-for-vue";
export default {
  components: {
    Loading,
    Editor,
    Toolbar
  },
  props: {
    visible: Boolean,
    id: String,
    pathType: String,
  },
  data() {
    return {
      labelWidth: "150px",
      inputWidth: "420px",
      title: "关联钉钉",
      loading: false,
      disabled: false,
      AgreeLoading: false,
      ruleForm: {
        phone: '',
        id: '',
      },
      rules: {
        phone: [
          { required: true, message: "请输入手机号", trigger: ["change", "bulr"] }
        ],
      },
    };
  },
  computed: {},
  created() {
    console.log('this.id', this.id)
    if (this.id != '') {
      this.ruleForm.id = this.id
    }

  },
  mounted() {

  },
  computed: {},
  methods: {
    //取消
    handleClose(formName) {
      this.$emit("update:visible", false);
    },
    submitForm(formName) {
      console.log(this.ruleForm);
      //创建确定
      this.$refs[formName].validate(valid => {
        if (valid) {
          this.AgreeLoading = true
          var data = {
            ...this.ruleForm
          }
            addDingTalk(data).then(res => {
              setTimeout(() => {
                this.handleClose()
                this.$message.success('关联成功')
                this.$emit('success')
                this.AgreeLoading = false
              }, 1000);
            }).finally(() => {
              this.AgreeLoading = false
            })
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
  }
};
</script>
<style lang="scss" scoped>
.ex-diolog {
  ::v-deep .ex--dialog--footer {
    border: none !important;
    padding: 0 !important;
  }

  ::v-deep .ex--dialog--main {
    padding: 10px 20px !important;
  }
}

.main {
  padding: 20px 20px;
}

.button_box {
  display: flex;
  justify-content: center;
}

.el-select {
  width: 500px !important;
}
</style>
